/**
 * Created with JetBrains PhpStorm.
 * User: ishowshao
 * Date: 12-7-19
 */

/**
 * @class FlyFight.model.User
 * @extends Zen.Model
 */
FlyFight.model.User = Zen.extend(Zen.Model, {
    isLogin: false,
    initModel: function () {
        this.addEvents(
            /**
             * @event
             * @param {String} username
             * @param {Array} onlineList
             */
            'login-success',
            /**
             * @event
             * @param {String} username
             * @param {Object} failureData
             */
            'login-failure'
        );
    },
    /**
     * @param {String} username
     * @return {Boolean}
     */
    login: function (username) {
        var that = this;
        if (username == '') {
            return false;
        }
        this.ajax({
            url: 'server/login.php',
            data: {
                username: username
            },
            dataType: 'json',
            success: function (result) {
                console.log(result);
                if (result.success) {
                    that.isLogin = true;
                    that.fireEvent('login-success', username, result.data);
                } else {
                    that.fireEvent('login-failure', username, result.data);
                }
            }
        });
        return true;
    }
});
